import logging
from typing import List, Literal

from gpt.model.base import ModelInstance
from gpt.model.cluster.controller_base import ModeControllerBase
from gpt.util.api__utils import APIMixin, api_remote
logger = logging.getLogger(__name__)


class RemoteModelController(APIMixin, ModeControllerBase):
    def __init__(
            self,
            urls: str,
            health_check_interval_secs: int = 5,
            health_check_timeout_secs: int = 30,
            check_health: bool = True,
            choice_type: Literal["latest_first", "random"] = "latest_first",
    ) -> None:
        APIMixin.__init__(
            self,
            urls=urls,
            health_check_path="/api/health",
            health_check_interval_secs=health_check_interval_secs,
            health_check_timeout_secs=health_check_timeout_secs,
            check_health=check_health,
            choice_type=choice_type,
        )
        ModeControllerBase.__init__(self)

    @api_remote(path="/api/controller/models", method="POST")
    async def register_instance(self, instance: ModelInstance) -> bool:
        pass

    @api_remote(path="/api/controller/models", method="DELETE")
    async def deregister_instance(self, instance: ModelInstance) -> bool:
        pass

    @api_remote(path="/api/controller/models")
    async def get_all_instances(
            self, model_name: str = None, healthy_only: bool = False
    ) -> List[ModelInstance]:
        pass

    @api_remote(path="/api/controller/heartbeat", method="POST")
    async def send_heartbeat(self, instance: ModelInstance) -> bool:
        pass
